package com.lewis.quartz.controller;

import com.lewis.core.annotation.Log;
import com.lewis.core.base.controller.BaseController;
import com.lewis.core.base.domain.BaseResult;
import com.lewis.core.base.page.TableDataInfo;
import com.lewis.core.enums.BusinessType;
import com.lewis.core.utils.office.excel.ExcelUtil;
import com.lewis.quartz.entity.SysJobLog;
import com.lewis.quartz.service.ISysJobLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 调度日志操作处理
 *
 * @author Lewis
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController extends BaseController {

    @Resource
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysJobLog sysJobLog) {
        startPage();
        List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        return getTableData(list);
    }

    /**
     * 导出定时任务调度日志列表
     */
    @Log(title = "任务调度日志" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public BaseResult export(SysJobLog sysJobLog) {
        List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
        return util.exportExcel(list, "调度日志");
    }

    /**
     * 根据调度编号获取详细信息
     */
    @GetMapping(value = "/{id}")
    public BaseResult getInfo(@PathVariable Long jobLogId) {
        return BaseResult.ok().setData(jobLogService.selectJobLogById(jobLogId));
    }

    /**
     * 删除定时任务调度日志
     */
    @Log(title = "定时任务调度日志" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobLogIds}")
    public BaseResult remove(@PathVariable Long[] jobLogIds) {
        return getResult(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @Log(title = "调度日志" , businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public BaseResult clean() {
        jobLogService.cleanJobLog();
        return BaseResult.ok();
    }
}
